package com.richinfo.app2.provider;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.context.annotation.Bean;
import org.springframework.integration.annotation.InboundChannelAdapter;
import org.springframework.integration.annotation.Poller;
import org.springframework.integration.core.MessageSource;
import org.springframework.messaging.support.GenericMessage;

import com.richinfo.common.entity.User;



/**
 * 消息生产者
 * 
* Created by WangXJ
* 2018-11-28 14:45
*/
@EnableBinding(value = MyOutput.class)
public class SinkProvider {
	
	private static Logger logger = LoggerFactory.getLogger(SinkProvider.class);
	
	@Bean
	@InboundChannelAdapter(value = MyOutput.OUTPUT,poller = @Poller(fixedDelay = "2000"))
	public MessageSource<User> timerMessageSource(){
//		Random r = new Random();
//		int age = r.nextInt(4);

		return () -> {
		    Double value = Math.random() * 10 % 5;
	        int age = value.intValue();
			User user = new User();
			user.setName("BB");
			user.setAge(age);
			
			return new GenericMessage<>(user); 
		};
	}
}











